//
//  TSFindBusinessCellViewModel.m
//  TaShuo
//
//  Created by N-X on 2018/3/20.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSFindBusinessCellViewModel.h"
#import "TSFindBusinessCollectionCell.h"
#import "TSFindBusinessItemViewModel.h"

@interface TSFindBusinessCellViewModel()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@end
@implementation TSFindBusinessCellViewModel
- (void)bindView:(UIView *)view
{
    UICollectionView * collectionView = (UICollectionView *)view;
    collectionView.delegate  = self;
    collectionView.dataSource = self;
    // 注册cell
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TSFindBusinessCollectionCell class]) bundle:nil] forCellWithReuseIdentifier:kFindBusinessItemCellID];
}

#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.businessItems.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TSFindBusinessCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kFindBusinessItemCellID forIndexPath:indexPath];
    TSFindBusinessItemViewModel * itemVM = self.businessItems[indexPath.item];
    [itemVM bindView:cell];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewFlowLayout * layout = (UICollectionViewFlowLayout *)layout;
    CGFloat itemH = (collectionView.nx_height - collectionView.contentInset.bottom);
    return CGSizeMake(itemH, itemH);
}
@end
